    <div class="main-content">
    	<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				$(document).ready(function () {

				 });
			</script>
	
			<!-- .breadcrumb -->
		</div>
		
        <!-- Main content -->
    <div class="page-content">
        <div class="page-header">
			<h1>添加服务</h1>
		</div>
        <div class="row">
			<div class="col-xs-12">
			<?php if (validation_errors()!=''){?>
	           <div id="info_msg" class="alert alert-danger"><?php echo validation_errors();?></div>
	        <?php }?>
	            <!-- general form elements disabled -->
	                <form id="usrform" role="form" action="<?php echo base_url().'admin/gasstation/add_service/'.$shop_id;?>" method="post"> 
	                	<div class="box-body" style="display: inline-block;width: 100%">
	                		<input type="text" id="services" style="display: none;" value='<?php echo json_encode($services);?>'>
	                		<div class="form-group col-xs-6">
					            <label>选择已有服务项目：</label>
					            <select name="services" style="width: 100%;" >
		                    	    <option value="">请选择</option>
		                    	    <?php foreach($services as $row):?>
		                    	    <option value="<?php echo $row['id']?>"><?php echo $row['service_name']?></option>
		                    		<?php endforeach?>
		                    	</select>
				            </div>
	                        <div class="form-group col-xs-6">
					            <label>服务名称：</label>
					            <input name="service_name" type="text" class="form-control" placeholder="输入 ..." value="" check-type="required" />
				            </div>
				            <div class="form-group col-xs-6">
					            <label>钉铛价格：</label>
					            <input name="app_price" type="text" class="form-control"    placeholder="输入 ..." value="" check-type="required">
				            </div>
				            <div class="form-group col-xs-6">
					            <label>门店价格：</label>
					            <input name="shop_price" type="text" class="form-control"   placeholder="输入 ..." value="" check-type="required">
				            </div>
				            <div class="form-group col-xs-6">
					            <label>服务id：</label>
					            <input name="goods_id" type="text" class="form-control"   placeholder="输入 ..." value="" check-type="required">
				            </div>
				            <div class="form-group col-xs-6">
				            	<div class="wh">
						            <label>服务分类：</label><br/>
						            <select name="service_type" check-type="required">
						            	<option value="">请选择</option>
						            	<option value="1">洗车服务</option>
						            	<option value="2">保养套餐</option>
						            </select>
						        </div>
				            </div>			    
	                	</div><!-- /.box-body -->
	                	<div class="clearfix form-actions">
						<div class="col-md-offset-3 col-md-9">
							<button id="btnSubmit" class="btn btn-info" type="submit">
								<i class="icon-ok bigger-110"></i>
								保存
							</button>

							&nbsp; &nbsp; &nbsp;
							<a class="btn" href="<?php echo base_url()."admin/gasstation/shops"?>">
								<i class="icon-undo bigger-110"></i>
								返回
							</a>
						</div>
					</div>
	                </form>
	        </div>
		</div>
    </div>
</div>
<script type="text/javascript">
	$("#usrform").validation();
	//保存
	$("#btnSubmit").on('click',function(event){
	  // 2.最后要调用 valid()方法。
	  if ($("#usrform").valid()==false){
	    return false;
	  }
	});
	var data = $('#services').val();
	data = JSON.parse(data);
	$('select[name="services"]').change(function(){
		var service_id = $(this).val();
		$.each(data,function(k,v){
			if(v['id'] == service_id){
				console.log(v);
				$('input[name="service_name"]').val(v['service_name']);
				$('input[name="app_price"]').val(v['app_price']);
				$('input[name="shop_price"]').val(v['shop_price']);
				$('input[name="goods_id"]').val(v['goods_id']);
				$('select[name="service_type"]').empty();
				if(v['service_type'] == 1){
					$('select[name="service_type"]').prepend("<option value='1' selected = 'selected'>洗车服务</option>");
				}else if(v['service_type'] == 2){
					$('select[name="service_type"]').prepend("<option value='2' selected = 'selected'>保养套餐</option>");
				}
				
			}
		})

		
		console.log(service_id,data);
	})
</script>